package com.xju.admin.controller;

import com.xju.admin.entity.Dictionary;
import com.xju.admin.entity.Question;
import com.xju.admin.entity.QuestionResult;
import com.xju.admin.service.DictionaryService;
import com.xju.admin.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@Controller
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    @Autowired
    private DictionaryService dictionaryService;

    @RequestMapping("question-list")
    public String questionList(Model model){
        QuestionResult questionList=questionService.findAll();
        model.addAttribute("questionResult",questionList);
        return "module_one/question_list";
    }

    @RequestMapping("question-modify")
    public String questionModify(@RequestParam(value = "quesId") String id,
                                 @RequestParam(value = "quesContent")String content,
                                 @RequestParam(value = "quesAnswer")String answer,
                                 @RequestParam(value = "quesDescribe")String describe,
                                 @RequestParam(value = "quesStatus") String status){
        questionService.modify(id,content,answer,describe,status);
        return "redirect:/question-list";
    }

    @RequestMapping("question-delete")
    @ResponseBody
    public Object questionDelete(String id){
        questionService.delete(id);
        Map<String,Object> map=new HashMap<>();
        map.put("ok",true);
        return map;
    }

    @RequestMapping("question-review")
    public String questionReview(Model model){
        QuestionResult questionResult=questionService.findSelected();
        model.addAttribute("questionResult",questionResult);
        return "module_one/question_review";
    }

    @RequestMapping("question-review-pass")
    public String pass(@RequestParam(value = "quesId") String id){
        questionService.pass(id);
        return "redirect:/question-review";
    }
}
